var subordinate={

	init:function(){
		var that = this;
		$(".add-sale").on('click',function(){
      // 显示窗口
			$('.add-sale-model').modal();
      // 注册提交
			that.doSubmit();
		})

		$("#cancelRed").on("click", function(){
			$('.add-sale-model').modal('hide');
		})

		$.ajax({
            url: COMMONURL + "/api/Company/GetSaleList?token=" + $.cookie('token'),
            type: "post",
            data: {

            },
            dataType: "json"
        }).done(function(redata) {
        		if(redata.recode=='1003'){
                window.location.href = '/nlogin.html';
                return;}
            if (redata.recode == '0000') {
                var compiled = _.template($("#saleTmp").html());
                var odata = redata.mod;
               
                $("#saleCont").html(compiled(odata));

              }
          });
	},

	doSubmit:function(){
		 $("#saleAddForm").validate({
            errorClass: 'error',
            rules: {
                sales_name:"required",
                sales_phone:"required"
                
            },
            messages: {
               sales_name:"",
               sales_phone:''
            },
            submitHandler: function(form) {
            	var data={
            		sales_name:$("#sales_name").val(),
            		sales_phone:$("#sales_phone").val()
            	}
            	$.ajax({
                    url: COMMONURL + "api/Company/AddSale?token=" + $.cookie('token'),
                    type: "post",
                    dataType: "json",
                    data: data,
                }).done(function(data) {
                	if(data.recode == '0000'){
                		  alert('操作成功');
                       window.location.reload();
                        }else{
                        	 alert(data.resmessage);
                        }
                });
            }
        });


	}

  
}

subordinate.init();